package com.erp.myAdapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.bean.ProdyctionClientBean
import com.erp.R
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_cb_tv.view.*
import java.util.*

/**
 * Created by Administrator on 2018/6/11/011.
 * 作者：刘洋
 */
class XGAdapter(context: Context, private val listguimingxi: ArrayList<ProdyctionClientBean.guimingxi>,var intgui : Int) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(context)

    override fun getCount(): Int {
        return listguimingxi.size
    }

    override fun getItem(position: Int): Any {
        return listguimingxi[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var v : View
        val vh: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_cb_tv, null)
            vh = ViewHolder(v)
            v.tag = vh
        } else {
            v=convertView
            vh = convertView.tag as ViewHolder
        }
        Myutil.settv(listguimingxi[position].guihao, vh.tvGuiHao)
        Myutil.settv(listguimingxi[position].name, vh.tvGuiMing)
        if (intgui == position) {
            vh.ivxg!!.setImageResource(R.mipmap.erp_xuan_true)
            vh.ivxg!!.setColorFilter(Color.BLUE)
        } else {
            vh.ivxg!!.setImageResource(R.mipmap.erp_xuan_false)
            vh.ivxg!!.setColorFilter(Color.BLACK)
        }
        return v
    }

    class ViewHolder(v : View) {
        var tvGuiHao = v.tv_GuiHao
        val tvGuiMing = v.tv_GuiMing
        val ivxg = v.iv_XuanGui
    }
}